package m.store.model;

import m.base.model.StoreInfo;
import m.common.model.*;
import m.common.model.type.FieldType;
import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@TableMeta(name="ts_goods_stock_record",description="商品库存记录")
public class GoodsStockRecord extends GoodsRecordModel implements MigrationModel {
    @Override
    public List<String> migrationOidList(String storeOid) throws Exception {
        return ModelQueryList.getModelList(this.getClass(),new String[]{"oid"},null,
                        QueryCondition.eq("store.oid",storeOid))
                .stream().map(Model::getOid).collect(Collectors.toList());
    }
    @LinkTableMeta(name="store_oid",table= StoreInfo.class,description="所属商户")
    private StoreInfo store;
    @LinkTableMeta(name="stock_oid",table= StockInfo.class,description="所属入库信息")
    private StockInfo stock;
    @LinkTableMeta(name="repository_oid",table= RepositoryInfo.class,description="仓库")
    private RepositoryInfo repository;
    @LinkTableMeta(name="goods_oid",table= StoreGoods.class,description="商品")
    private StoreGoods goods;
    @LinkTableMeta(name="out_record_oid",table= GoodsOutRecord.class,description="出库记录|退货")
    private GoodsOutRecord outRecord;
    @LinkTableMeta(name="back_record_oid",table= GoodsStockRecord.class,description="退记录")
    private GoodsStockRecord backRecord;
    @FieldMeta(name="oper_date",type= FieldType.DATE,description="操作时间")
    private Date operDate;
    @FieldMeta(name="price",type= FieldType.DOUBLE,description="单价")
    private Double price;
    @FieldMeta(name="stock_num",type= FieldType.INT,description="库存数量|1.入库数量")
    private Integer stockNum;
    @FieldMeta(name="preferential",type= FieldType.DOUBLE,description="总优惠")
    private Double preferential;
    @FieldMeta(name="stock_amount",type= FieldType.DOUBLE,description="库存金额|1.入库数量*单价-优惠")
    private Double stockAmount;
    @FieldMeta(name="preferential_price",type= FieldType.DOUBLE,description="优惠后单价")
    private Double preferentialPrice;
    @FieldMeta(name = "remark",type = FieldType.STRING,length = 500,description = "备注")
    private String remark;

    //冗余信息
    @FieldMeta(name="refund_num",type= FieldType.INT,defaultValue = "0",description="退货数量")
    private Integer refundNum;
    @FieldMeta(name="refund_amount",type= FieldType.DOUBLE,defaultValue = "0",description="退货金额")
    private Double refundAmount;
    @FieldMeta(name="sale_num",type= FieldType.INT,defaultValue = "0",description="销售数量")
    private Integer saleNum;
    @FieldMeta(name="surplus_num",type= FieldType.INT,defaultValue = "0",description="剩余数量")
    private Integer surplusNum;
    @FieldMeta(name="surplus_amount",type= FieldType.DOUBLE,defaultValue = "0",description="剩余金额")
    private Double surplusAmount;

    public GoodsStockRecord getBackRecord() {
        return backRecord;
    }

    public void setBackRecord(GoodsStockRecord backRecord) {
        this.backRecord = backRecord;
    }

    public RepositoryInfo getRepository() {
        return repository;
    }

    public void setRepository(RepositoryInfo repository) {
        this.repository = repository;
    }

    public GoodsOutRecord getOutRecord() {
        return outRecord;
    }

    public void setOutRecord(GoodsOutRecord outRecord) {
        this.outRecord = outRecord;
    }

    public Integer getSaleNum() {
        return saleNum;
    }

    public void setSaleNum(Integer saleNum) {
        this.saleNum = saleNum;
    }

    public Double getPreferentialPrice() {
        return preferentialPrice;
    }

    public void setPreferentialPrice(Double preferentialPrice) {
        this.preferentialPrice = preferentialPrice;
    }

    public StoreInfo getStore() {
        return store;
    }

    public void setStore(StoreInfo store) {
        this.store = store;
    }

    public StockInfo getStock() {
        return stock;
    }

    public void setStock(StockInfo stock) {
        this.stock = stock;
    }

    public StoreGoods getGoods() {
        return goods;
    }

    public void setGoods(StoreGoods goods) {
        this.goods = goods;
    }

    public Date getOperDate() {
        return operDate;
    }

    public void setOperDate(Date operDate) {
        this.operDate = operDate;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public Integer getStockNum() {
        return stockNum;
    }

    public void setStockNum(Integer stockNum) {
        this.stockNum = stockNum;
    }

    public Double getPreferential() {
        return preferential;
    }

    public void setPreferential(Double preferential) {
        this.preferential = preferential;
    }

    public Double getStockAmount() {
        return stockAmount;
    }

    public void setStockAmount(Double stockAmount) {
        this.stockAmount = stockAmount;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Integer getRefundNum() {
        return refundNum;
    }

    public void setRefundNum(Integer refundNum) {
        this.refundNum = refundNum;
    }

    public Double getRefundAmount() {
        return refundAmount;
    }

    public void setRefundAmount(Double refundAmount) {
        this.refundAmount = refundAmount;
    }

    public Integer getSurplusNum() {
        return surplusNum;
    }

    public void setSurplusNum(Integer surplusNum) {
        this.surplusNum = surplusNum;
    }

    public Double getSurplusAmount() {
        return surplusAmount;
    }

    public void setSurplusAmount(Double surplusAmount) {
        this.surplusAmount = surplusAmount;
    }
}
